<?php
class material_finder_material_giftreplace{

    var $addon_cols = "disabled,check_status";
    var $column_edit = '操作';
    var $column_edit_width = "100";

    function column_edit($row){
        $user = kernel::single('desktop_user');
       
        $fid = $_GET['_finder']['finder_id'];
        $btn = '<a href="index.php?app=material&ctl=admin_material_giftreplace&act=edit&p[0]='.$row['rep_id'].'&finder_id='.$_GET[_finder][finder_id].'" target="_blank">编辑</a>';

        if ($row[$this->col_prefix.'check_status'] == '1' && $user->has_permission('material_giftreplace_check')){
            $btn.= ' '.sprintf('<a href="javascript:if (confirm(\'确认要审核吗？\')){W.page(\'index.php?app=material&ctl=admin_material_giftreplace&act=do_check&p[0]=%s&finder_id=%s\', $extend({method: \'get\'}, JSON.decode({})), this);}void(0);" target="">审核</a>',$row['rep_id'],$fid);

        }

        if ($row[$this->col_prefix.'disabled'] == 'true'){
            $btn.= ' '.sprintf('<a href="javascript:if (confirm(\'确认要关闭吗？\')){W.page(\'index.php?app=material&ctl=admin_material_giftreplace&act=do_update&p[0]=%s&oper=close&finder_id=%s\', $extend({method: \'get\'}, JSON.decode({})), this);}void(0);" target="">关闭</a>',$row['rep_id'],$fid);
        }else{
            $btn.= ' '.sprintf('<a href="javascript:if (confirm(\'确认要启用吗？\')){W.page(\'index.php?app=material&ctl=admin_material_giftreplace&act=do_update&p[0]=%s&oper=open&finder_id=%s\', $extend({method: \'get\'}, JSON.decode({})), this);}void(0);" target="">启用</a>',$row['rep_id'],$fid);
        }
        
        return $btn;
    }

    var $column_use_expire='状态';
    function column_use_expire($row){

        $statusMdl = app::get('material')->model('basic_giftreplace');
        $rep_id = $row['rep_id'];
        $status = $statusMdl->getList('disabled',array('rep_id'=>$rep_id));
       
        if($status[0]['disabled'] == 'true'){
            return '开启';
        }else{
            return '关闭';
        }
    }

    var $column_shop='店铺名称';
    function column_shop($row){
        $statusMdl = app::get('material')->model('basic_giftreplace');
        $shop      = app::get('ome')->model('shop');
        $rep_id    = $row['rep_id'];
        $shopIds   = $statusMdl->getList('shopIds',array('rep_id'=>$rep_id));
        $shoparray = explode(',',$shopIds[0]['shopIds']);
        $shoplist['shop_id'] = $shoparray;
        $shop_names= $shop->getList('name',$shoplist);
        if($shop_names) {
            foreach($shop_names as $key=>$name) {
                $shopstr .= $shop_names[$key]['name'];
                if($key>0) $shopstr .= ',';
            }
        }else {
            $shopstr   = $shopIds[0]['shopIds'];
        }
        return $shopstr;
    }

}

